package com.walker.taogong.datasource.postgresql;

import java.util.Dictionary;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * TODO: describe me
 */
public class Activator implements BundleActivator
{
    private static Logger log = LoggerFactory.getLogger(Activator.class);

    private void message(BundleContext context,String prefix,String postfix) {
        @SuppressWarnings("unchecked")
        Dictionary<String,String> list = context.getBundle().getHeaders();
        String symbol = list.get("Bundle-SymbolicName");
        String name   = list.get("Bundle-Name");
        String vers   = list.get("Bundle-Version");
        Activator.log.info((prefix == null ? "Bundle" : prefix) + " " + symbol + " (" + name + " " + vers + ")" + (postfix == null ? "" : " " + postfix));
        return;
    }
    
    /**
     * Called by the OSGI framework during startup.
     */
    @Override
    public void start(BundleContext context) throws Exception
    {
        this.message(context,null,"starting...");
        this.message(context,null,"started.");
    }

    /**
     * Called by the OSGi framework during shutdown.
     */
    @Override
    public void stop(BundleContext context) throws Exception
    {
        this.message(context,null,"stopping...");
        this.message(context,null,"stopped.");
    }
}
